home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!guardian!slip30
- From: genesis@forbin.com (Dances with Demons)
- Newsgroups: comp.lang.c++
- Subject: Question about visibility of local variables
- Date: Mon, 04 Mar 96 18:49:44 GMT
- Organization: The Genesis Project
- Message-ID: <4hfkpc$9em@guardian.forbin.com>
- NNTP-Posting-Host: slip30.forbin.com
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- I am in the process of learning C++ which surprised me in being
- as awesome as everyone kept telling me. It is literally better
- than anything I ever expected. I ran into one dark area for me
- in the area of automatic variables.
- It said in the book I'm studying, "Object-Oriented Programming
- in C++, by Robert Lafore", that when a function is executed, the
- and the variable is defined, it will continue to exist until the
- function is exited. When this happens, the memory that the variable
- is freed up and is used by other variables/function calls, etc.
-
- The question is: When you define a variable in main(), and call another
- function, or even when defining a local variable in a function that calls
- another function, why are the local variables not destroyed.
- I had a thought that maybe since main() called the function, it still had
- control, (at least as far as variable usage went) and therefore didn't
- free up the memory until the function is actually completed, (End
- of the program), but I wasn't sure. Could someone please verify that this is
- indeed the case, or refute it and give me the real reason.
-
- I thank you in advance, any help will be greatly appreciated.
- Thomas Klemensen - genesis@forbin.com
-